package cn.tansanqinger.controller.chatroom;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.pojo.Unauthorized;
import cn.tansanqinger.service.chatroom.IFriendlistService;
import cn.tansanqinger.service.chatroom.IUnauthorizedService;
import cn.tansanqinger.service.hymenu.IHyMenuServer;
import cn.tansanqinger.util.PageData;

@RequestMapping("/exchange")
@Controller
public class LinkmanController {
	
	@Autowired
	private IHyMenuServer hyMenuServer;
	@Autowired
	private IFriendlistService fservice;
	@Autowired
	private IUnauthorizedService uservice;
	
	@RequestMapping("/linkman")
	public ModelAndView linkman(ModelAndView mv, HttpServletRequest request) {
		mv = hyMenuServer.selectHyMenuAll(mv);
		mv.addObject("user", request.getSession().getAttribute("user"));
		mv.addObject("friendlist", fservice.selectMessage(request));
		mv.setViewName("chatroom/linkman");
		return mv;
	}
	
	@RequestMapping("/linkman2")
	@ResponseBody
	public PageData linkman2(HttpServletRequest request) {
		PageData pd = new PageData();
		pd.put("user", request.getSession().getAttribute("user"));
		pd.put("friendlist", fservice.selectMessage(request));
		return pd;
	}
	
	//查询用户或者群聊
	@RequestMapping("/selectLinkmanAndGroupChat")
	@ResponseBody
	public PageData selectLinkmanAndGroupChat(HttpServletRequest request) {
		return fservice.addNewLinkmanAndGroupChat(request);
	}
	
	//单一数据，通过id
	@RequestMapping("/selectUser")
	@ResponseBody
	public PageData selectUser(HttpServletRequest request) {
		return fservice.selectUser(request);
	}
	
	//添加用户或者群聊
	@RequestMapping("/addNewLinkmanAndGroupChat")
	@ResponseBody
	public PageData addNewLinkmanAndGroupChat(HttpServletRequest request) {
		return uservice.add(request);
	}
	
	//新的好友信息
	@RequestMapping("/newLinkman")
	@ResponseBody
	public List<Unauthorized> newLinkman(HttpServletRequest request){
		return uservice.selectAll(request);
	}
	
	//拒绝添加好友
	@RequestMapping("/refusedToAdd")
	@ResponseBody
	public PageData refusedToAdd(HttpServletRequest request) {
		return uservice.refusedToAdd(request);
	}
	
	//同意添加好友
	@RequestMapping("/agreeToAdd")
	@ResponseBody
	public PageData agreeToAdd(HttpServletRequest request) {
		return uservice.agreeToAdd(request);
	}
	
}
